package com.zp.self.module.spring常用.request参数获取;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author By ZengPeng
 * @Description 程序处理时区
 * @date in  2021/1/11 11:01
 * @Modified By
 */
@RestController
@RequestMapping("/req")
public class RequestController {
    //测试参数校验
    @GetMapping(value = "/getEquipment")
    public Object getEquipment(@Valid @RequestParam(required = false,defaultValue = "10")  @Max(value = 100, message = "name最大长度为100") int limit){
        System.out.println();
        return "ok";
    }


    @RequestMapping(value = "/postStr",method = RequestMethod.POST)
    @ResponseBody
    public Object post(@RequestBody String str) {
        System.out.println(str);
        return str;
    }

    @RequestMapping(value = "/postMap",method = RequestMethod.POST)
    @ResponseBody
    public Object post(@RequestBody Map<String,Object> str) {
        System.out.println(str);
        return str;
    }

    @RequestMapping(value = "/postList",method = RequestMethod.POST)
    @ResponseBody
    public Object post(@RequestBody List<String> list) {
        System.out.println(list);
        return list;
    }

    @RequestMapping(value = "/Fleet/Equipment/ID/{oemIsoIdentifier}/CumulativeFuelUsed/{startDateTimeUTC}/{endDateTimeUTC}/{pageNumber}",method = RequestMethod.GET)
    public @JacksonXmlProperty(localName = "FuelUsedMessages") Map getCumulativeFuelUsed(@PathVariable String oemIsoIdentifier, HttpServletRequest request,
                                                                                         @PathVariable("startDateTimeUTC") @DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")Date startDateTimeUTC,
                                                                                         @PathVariable("endDateTimeUTC")  @DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date endDateTimeUTC,
                                                                                         @Valid  @Max(value = 100, message = "The maximum length of PageNumber is 100") @Min(value = 0, message = "The minimum value of PageNumber is 0")
                                     @PathVariable int pageNumber,
                                                                                         @Valid  @Max(value = 100, message = "The maximum length of limit is 100") @Min(value = 0, message = "The minimum limit is 0")
                                     @RequestParam(required = false,defaultValue = "10") int limit) {

        System.out.println(startDateTimeUTC);
        Map map =new HashMap();
        map.put("aa",startDateTimeUTC);
        map.put("bb",endDateTimeUTC);
        //查询当前的设备列表
        return map;
    }
}
